package city.spring.modules.sitting.service.impl;

import city.spring.modules.sitting.entity.SittingRecordEntity;
import city.spring.modules.sitting.repository.SittingRecordRepository;
import city.spring.modules.sitting.service.SittingRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Service：医生坐诊记录
 *
 * @author 侯坤林
 * @date 2020-07-16 15:48:26
 */
@CacheConfig(cacheNames = {SittingRecordServiceImpl.CACHE_NAME})
@Transactional(rollbackFor = Throwable.class)
@Service
public class SittingRecordServiceImpl extends ServiceImpl<SittingRecordRepository, SittingRecordEntity> implements SittingRecordService {

    @Override
    public void saveSittingRecord(SittingRecordEntity entity) {
        if (!save(entity)) {
            throw new RuntimeException("保存信息失败");
        }
    }

    @Override
    public void updateSittingRecord(SittingRecordEntity entity) {
        // 使用 updateById(entity); 修改数据时，将会修改 entity 对象中所有非null数据，如果某个字段为null，将会忽略该字段的修改
        boolean update = updateById(entity);
        if (!update) {
            throw new RuntimeException("修改信息失败");
        }
    }

    @Override
    public void deleteSittingRecord(String primaryKey) {
        removeById(primaryKey);
    }

    @Override
    public void deleteSittingRecord(List<String> primaryKeys) {
        removeByIds(primaryKeys);
    }
}